// Copyright (C) joyinter
// All rights reserved.
// 
// Author : Jiang Li
// Date   : 2004-7-29

#include "stdafx.h"
#include ".\userpagectrl.h"


// class CJoyUserPageContainer

IMPLEMENT_DYNAMIC(CJoyUserPageContainer, CJoyPageContainer)

//##ModelId=44C4B5D8036D
CJoyUserPageContainer::CJoyUserPageContainer(CJoyUserPageCtrl* pageCtrl)
{
    m_pageCtrl = pageCtrl;
    m_frameColor.SetValue(0x00000000);
    m_cornerSize = 0;
}

//##ModelId=44C4B5D8036F
CJoyUserPageContainer::~CJoyUserPageContainer(void)
{
}

BEGIN_MESSAGE_MAP(CJoyUserPageContainer, CJoyPageContainer)
END_MESSAGE_MAP()

//##ModelId=44C4B5D80360
void CJoyUserPageContainer::CM_LoadSkin(CJoyXmlElement* pSkinElem)
{
    __super::CM_LoadSkin(pSkinElem);

    m_frameColor.SetValue(pSkinElem->ReadIntX("frame_color", m_frameColor.GetValue()));

    m_cornerSize = (int)pSkinElem->ReadIntD("corner_size", m_cornerSize);
}


//##ModelId=44C4B5D80363
void CJoyUserPageContainer::CM_Draw(Graphics& graph)
{
    __super::CM_Draw(graph);

//    CJoyPageTabSet* tabSet = m_pageCtrl->m_tabSet;

    int w = m_area.Width();
    int h = m_area.Height();
    int wc = w-m_cornerSize;
    int hc = h-m_cornerSize;

    CRect tabArea(0, 0, 0, 0);
    CJoyCheckBox* selTab = m_pageCtrl->m_tabGroup.GetSel();
    if(selTab != NULL)
    {
        tabArea = selTab->GetArea();
    }

    Pen framePen(m_frameColor);
    GraphicsPath path;
    Point p1(m_cornerSize, 0);
    Point p2(0, m_cornerSize);
    Point p3(0, hc-1);
    Point p4(m_cornerSize, h-1);
    Point p5(wc-1, h-1);
    Point p6(w-1, hc-1);
    Point p7(w-1, 0);
    path.AddLine(p1, p2);
    path.AddLine(p3, p4);
    path.AddLine(p5, p6);
    path.AddLine(p6, p7);

    graph.DrawLine(&framePen, p1.X, p1.Y, tabArea.left, 0);
    graph.DrawLine(&framePen, tabArea.right, 0, w-1, 0);

    graph.DrawLine(&framePen, m_cornerSize+1, 2, tabArea.left-1, 2);
    graph.DrawLine(&framePen, tabArea.right, 2, w, 2);
    graph.DrawLine(&framePen, m_cornerSize, 3, tabArea.left-1, 3);
    graph.DrawLine(&framePen, tabArea.right, 3, w, 3);

    graph.DrawPath(&framePen, &path);
}


// class CJoyUserPageCtrl

//##ModelId=44C4B5D8037E
CJoyUserPageCtrl::CJoyUserPageCtrl(void)
{
    m_name = "user_page_ctrl";
    m_align = AT_Client;

}

//##ModelId=44C4B5D8038A
CJoyUserPageCtrl::~CJoyUserPageCtrl(void)
{
}

//##ModelId=44C4B5D8037C
CJoyPageContainer* CJoyUserPageCtrl::CreateContainer()
{
    return new CJoyUserPageContainer(this);
}

BEGIN_MESSAGE_MAP(CJoyUserPageCtrl, CJoyPageCtrl)
    ON_WM_CREATE()
END_MESSAGE_MAP()

//##ModelId=44C4B5D8038D
int CJoyUserPageCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CJoyPageCtrl::OnCreate(lpCreateStruct) == -1)
        return -1;

    return 0;
}
